package org.steven0lisa.typhoon.ui;

import org.steven0lisa.typhoon.bean.TyphoonStatus;

import com.baidu.mapapi.map.Geometry;
import com.baidu.mapapi.map.Graphic;
import com.baidu.mapapi.map.GraphicsOverlay;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.Symbol;

public class TyphoonWindOverlay extends GraphicsOverlay{
	
	long currentSevenId = -1;
	long currentTenId = -1;
	
	TyphoonStatus currentStatus = null;

	public TyphoonWindOverlay(MapView arg0) {
		super(arg0);
	}
	
	
	public void toggleDisplayStatus(TyphoonStatus status){
		if(currentStatus != null && currentStatus.id.equals(status.id)){
			hideCurrent();
			MainActivity.instance.updateMap();
			return;
		}
		hideCurrent();
		show(status);
	}
	
	private void show(TyphoonStatus status) {
		int sevenRing = Integer.parseInt(status.seven_ring);
		int tenRing = Integer.parseInt(status.ten_ring);
		if(sevenRing > 0){
			Geometry sevenLevelGeometry = new Geometry();
			sevenLevelGeometry.setCircle(status.getPoint(), sevenRing * 1000);
			Symbol palaceSymbol = new Symbol();//创建样式  
			Symbol.Color palaceColor = palaceSymbol.new Color();//创建颜色  
			palaceColor.red = 0;//设置颜色的红色分量  
			palaceColor.green = 0;//设置颜色的绿色分量  
			palaceColor.blue = 255;//设置颜色的蓝色分量  
			palaceColor.alpha = 150;//设置颜色的alpha值  
			palaceSymbol.setSurface(palaceColor,1,3);//设置样式参数，颜色：palaceColor是否填充距形：是线  
			Graphic palaceGraphic = new Graphic(sevenLevelGeometry, palaceSymbol);
			currentSevenId = setData(palaceGraphic);
		}
		if(tenRing > 0){
			Geometry tenLevelGeometry = new Geometry();
			tenLevelGeometry.setCircle(status.getPoint(), tenRing * 1000);
			Symbol palaceSymbol = new Symbol();//创建样式  
			Symbol.Color palaceColor = palaceSymbol.new Color();//创建颜色  
			palaceColor.red = 0;//设置颜色的红色分量  
			palaceColor.green = 255;//设置颜色的绿色分量  
			palaceColor.blue = 255;//设置颜色的蓝色分量  
			palaceColor.alpha = 150;//设置颜色的alpha值  
			palaceSymbol.setSurface(palaceColor,1,3);//设置样式参数，颜色：palaceColor是否填充距形：是线  
			Graphic palaceGraphic = new Graphic(tenLevelGeometry, palaceSymbol);
			currentTenId = setData(palaceGraphic);
		}
		MainActivity.instance.updateMap();
		currentStatus = status;
		
	}


	private void hideCurrent(){
		if(currentSevenId > 0){
			removeGraphic(currentSevenId);
			currentSevenId = -1;
		}
		if(currentTenId > 0){
			removeGraphic(currentTenId);
			currentTenId = -1;
		}
		currentStatus = null;
	}
	

}
